package conf2.ui;

import conf2.model.ESpecialCard;
import conf2.text.Cards;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.Stroke;
import javax.swing.BorderFactory;

public class SpecialCardMiniature extends ImagePanel
{

    private boolean crossedOut = false;
    private String tooltip;
    private Color normal = new Color(0, 0, 0, 64);
    private Color played = new Color(0, 0, 0, 168);
    public static final int CARD_WIDTH = Images.getSmallSpecialCard(ESpecialCard.A_KING_REVEALED).getWidth(null);
    public static final int CARD_HEIGHT = Images.getSmallSpecialCard(ESpecialCard.A_KING_REVEALED).getHeight(null);

    public SpecialCardMiniature(ESpecialCard toModel)
    {
        Image img = Images.getSmallSpecialCard(toModel);

        setHoverSensitive(false);
        tooltip = "<html><i>[Opponent special card]</i><br>" + Cards.getSpecialCardDescription(toModel) + "</html>";
        setToolTipText(tooltip);
        setImage(img);

        setBorder(BorderFactory.createLineBorder(Color.BLACK));
    }

    public void setCrossedOut(boolean b)
    {
        crossedOut = b;
        if (crossedOut) {
            setToolTipText(Cards.DISABLED_OPPONENT_SPECIAL_CARD_TOOLTIP);
        } else {
            setToolTipText(tooltip);
        }
    }

    @Override
    protected void paintComponent(Graphics g_)
    {
        super.paintComponent(g_);
        Graphics2D g = (Graphics2D) g_;
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        if (crossedOut) {
            g.setColor(played);
        } else {
            g.setColor(normal);
        }

        g.fillRect(0, 0, getWidth(), getHeight());

        if (crossedOut) {
            Graphics2D g2 = (Graphics2D) g;
            g2.setColor(Color.RED);
            Stroke oldStroke = g2.getStroke();
            g2.setStroke(new BasicStroke(3.0f));
            g2.drawLine(5, 5, getWidth() - 6, getHeight() - 6);
            g2.drawLine(getWidth() - 6, 5, 5, getHeight() - 6);
            g2.setStroke(oldStroke);
        }
    }
}
